package com.polaris.live.popup

import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.StringUtils
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.R
import com.polaris.live.adapter.ReportAdapter
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.requestLoading
import com.polaris.live.common.util.ToastGravity
import com.polaris.live.databinding.PopupOptionReportBinding
import com.polaris.live.net.userService
import com.polaris.live.resp.bean.ReportBean
import com.polaris.live.resp.go_resp.ComplaintBean
import com.polaris.live.translation.R.string

/**
 * ReportOptionPopup
 *
 * @author Created by 半仙 on 2023/10/27/027 10:11
 */
class ReportOptionPopup(
    context: Context,
    private val mViewModel: BaseViewModel,
    private val nickName: String,
    private val otherUserId: Long,
    private val sourceType: Int,
    private val objectId: Long? = null,
) : BottomPopupView(context) {

    private lateinit var mBinding: PopupOptionReportBinding

    private val mAdapter: ReportAdapter by lazy {
        ReportAdapter()
    }

    override fun getImplLayoutId(): Int {
        return R.layout.popup_option_report
    }

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupOptionReportBinding.bind(popupImplView)
        mBinding.recycler.apply {
            adapter = mAdapter
            layoutManager = LinearLayoutManager(context)
        }
        mAdapter.setList(list)
        mBinding.tvReportUserName.text = nickName
        mAdapter.setOnItemClickListener { _, _, position ->
            if (mAdapter.data[position].type != -1) {
                val complaintBean =
                    ComplaintBean(otherUserId, objectId, sourceType, mAdapter.data[position].type)
                mViewModel.requestLoading({ userService.complaintIt(complaintBean) }, {
                    reportSuccess()
                })
            } else {
                dismiss()
            }
        }
    }

    private fun reportSuccess() {
        ToastGravity.showGravity(StringUtils.getString(string.report_success))
        dismiss()
    }

    companion object {

        val list = mutableListOf(
            ReportBean(StringUtils.getString(string.porn_content), 1),
            ReportBean(StringUtils.getString(string.advertising), 5),
            ReportBean(StringUtils.getString(string.underage), 2),
            ReportBean(StringUtils.getString(string.no_face), 3),
            ReportBean(StringUtils.getString(string.not_other_self), 6),
            ReportBean(StringUtils.getString(string.cancel), -1)
        )
    }

}